package jp.dodododo.aop.interceptors;

import jp.dodododo.aop.annotation.Enhance;
import jp.dodododo.aop.annotation.HandleThrowable;

import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * {@.en ThrowsInterceptor to trace the exception.}
 * 
 * <br/>
 * 
 * {@.ja 例外をトレースするためのThrowsInterceptorです。}
 * 
 * @see ThrowsInterceptor
 * 
 * @author Satoshi Kimura
 */
@Enhance(false)
public class TraceThrowsInterceptor extends ThrowsInterceptor {

	private static final Log logger = LogFactory.getLog(TraceThrowsInterceptor.class);

	private static final TraceThrowsInterceptor INSTANCE = new TraceThrowsInterceptor();

	public static TraceThrowsInterceptor getInstance() {
		return INSTANCE;
	}

	/**
	 * {@.en <code>call "logger.debug(t.getMessage(), t);"</code> and <code>"throw t;"</code>}
	 * 
	 * <br/>
	 * 
	 * {@.ja logger.debug(t.getMessage(), t); をコールした後に、例外をスローします。}
	 * 
	 * @param t
	 * @param invocation
	 * @throws Throwable
	 */
	@HandleThrowable
	public void handle(Throwable t, MethodInvocation invocation) throws Throwable {
		logger.debug(t.getMessage(), t);
		throw t;
	}

}
